import cv2
import face_have as ha

WIDTH = 1440
HEIGHT = 1920
photos = list()    # 图像样本
lables = list()    # 标签列表
num = 0


ha.load_employee_pic()
# 摄像头读取一帧后匹配 查看有没有匹配得 然后 摄像头一直处于开启状态
video = cv2.VideoCapture(0, cv2.CAP_DSHOW)
success, frame = video.read()
while success and cv2.waitKey(1) == -1:
    cv2.imshow("frame", frame)
    # 将当前帧转化为灰度图像
    gary = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    # 判断是否有人脸
    if ha.found_face(gary):
        # 将当前帧转化为统一大小
        gary = cv2.resize(gary, (WIDTH, HEIGHT))
        gary_gaosi = cv2.GaussianBlur(gary, (3,3), 0, 0)
        # 识别图像 看是否人脸在数据库中
        na = ha.recognize_face(gary)
        if na != None:
            print("开门成功")
            print(na)
            num += 1
            print(num)

        else:
            print("有陌生人闯入")
    success, frame = video.read()






